// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async remoteOne({ state: { API, MAP, one } }) {
    const obj = await API.getOne(one, API.transTip(MAP.tipOne))
    const doorStatus = await API.getStatus(one, API.transTip(MAP.tipStatus))
    return transOne(obj, doorStatus)
  },
}

// ============================== 转换方法 ============================== //

const transOne = (obj, doorStatus) => {
  if (!CORE.isEmpty(obj.alarmDtos)) {
    const { id, alarmTime: time, alarmTypeName: name } = obj.alarmDtos
    obj.alarmId = id
    obj.alarmContent = `${CORE.timeStr(time)} 产生${name}`.replace(/((告|报)警)?$/, CORE.MAP.ALARM)
  }

  obj.devicePointId = obj.id // 反控 ID
  obj.status = obj.status === 4 ? 4 : 5 // 门禁点状态
  obj.doorStatus = doorStatus || 2 // 开关门状态

  return obj
}
